package com.chuantou.yuba.ui.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.view.View.OnClickListener;

import com.chuantou.yuba.R;
import com.chuantou.yuba.util.Constants;

public class SexPickView extends FrameLayout implements OnClickListener {
	private int mSex = Constants.SEX_MALE;
	private TextView mMaleView;
	private TextView mFemaleView;

	public SexPickView(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		setupViews();
	}

	public SexPickView(Context context, AttributeSet attrs) {
		super(context, attrs);
		setupViews();
	}

	public SexPickView(Context context) {
		super(context);
		setupViews();
	}

	private void setupViews() {
		LayoutInflater inflater = LayoutInflater.from(getContext());
		inflater.inflate(R.layout.pick_sex, this, true);
		mMaleView = (TextView) findViewById(R.id.male);
		mMaleView.setOnClickListener(this);
		mFemaleView = (TextView) findViewById(R.id.female);
		mFemaleView.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.male:
			mMaleView.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.sex_selected, 0);
			mFemaleView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
			mSex = Constants.SEX_MALE;
			break;
		case R.id.female:
			mMaleView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
			mFemaleView.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.sex_selected, 0);
			mSex = Constants.SEX_FEMALE;
			break;
		default:
			break;
		}
	}

	public int getSex() {
		return mSex;

	}
}
